<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <%@ include file="inc/css.jsp" %>
    <%@ include file="inc/js.jsp" %>
</head>
<body class="childrenBody">
<form class="layui-form layui-row">
    <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
        <div class="layui-form-item" style="margin-top: 15px;">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" value="${sessionScope.session_master.name}" disabled class="layui-input layui-disabled"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="password" onblur="checkPwd(this)" placeholder="请输入旧密码" lay-verify="required" class="layui-input pwd">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" value="" placeholder="请输入新密码" lay-verify="required|newPwd" id="oldPwd" class="layui-input pwd">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" value="" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="saveInfo">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
</body>

<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            $ = layui.jquery;

        //添加验证规则
        form.verify({
            newPwd: function (value, item) {
                if (value.length < 6) {
                    return "密码长度不能小于6位";
                }
            },
            confirmPwd: function (value, item) {
                if (!new RegExp($("#oldPwd").val()).test(value)) {
                    return "两次输入密码不一致，请重新输入！";
                }
            }
        });

        form.on("submit(saveInfo)", function (data) {
            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
            // 实际使用时的提交信息
            $.post("modifyPwd", {
                newPwd: $("#oldPwd").val()
            }, function (res) {
                if (res === 1) {
                    layer.alert('密码修改成功，稍后将跳转到登录界面', {
                        skin: 'layui-layer-molv' //样式类名  自定义样式
                        , closeBtn: 0    // 是否显示关闭按钮
                        , anim: 1 //动画类型
                        , btn: ['确定'] //按钮
                        , icon: 6    // icon
                        , yes: function () {
                            parent.location.href = 'login';
                        }
                    });
                } else {
                    top.layer.close(index);
                    top.layer.msg("服务器错误，请联系管理员！");
                }
            });
            return false;
        });


    });

    function checkPwd(_self) {
        $.post("check/oldPwd", {
            oldPwd: $(_self).val()
        }, function (result) {
            if (result === 0) {
                layer.msg("旧密码错误，请重新输入！");
                $(_self).val('');
                $(_self).focus();
            }
        });
    }
</script>

</html>